/*
		ServEngine framework library
		A library to fast develop JEE online applications
	
		Copyright 2008 José Ignacio de Córdoba Álvaro

		Licensed under the Apache License, Version 2.0 (the "License");
		you may not use this file except in compliance with the License.
		You may obtain a copy of the License at

				http://www.apache.org/licenses/LICENSE-2.0

		Unless required by applicable law or agreed to in writing, software
		distributed under the License is distributed on an "AS IS" BASIS,
		WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
		See the License for the specific language governing permissions and
		limitations under the License.
	
		Jose Ignacio de Cordoba Alvaro
		http://ignacio.decordoba.com
*/

package com.servengine.util;

import java.io.IOException;
import java.io.OutputStream;

import java.io.PrintWriter;

import javax.servlet.ServletOutputStream;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;

public class RedirectingServletResponse extends HttpServletResponseWrapper {
 
    RedirectServletStream out;
 
    public RedirectingServletResponse(HttpServletResponse response, OutputStream out) {
        super(response);
        this.out = new RedirectServletStream(out);
    }
/*		public ServletResponse getResponse()
		{
			return super.getResponse();
		}
		public void setResponse(ServletResponse value)
		{
			super.setResponse(value);
		}*/
    /* (non-Javadoc)
     * @see javax.servlet.ServletResponse#flushBuffer()
     */
    public void flushBuffer() throws IOException {
        out.flush();
    }
 
    /* (non-Javadoc)
     * @see javax.servlet.ServletResponse#getOutputStream()
     */
    public ServletOutputStream getOutputStream() throws IOException {
        return out;
    }
 
    /* (non-Javadoc)
     * @see javax.servlet.ServletResponse#getWriter()
     */
    public PrintWriter getWriter() throws IOException {
        return new PrintWriter(out);
    }

    private static class RedirectServletStream extends ServletOutputStream {
        OutputStream out;
 
        RedirectServletStream(OutputStream out) {
            this.out = out;
        }
 
        public void write(int param) throws java.io.IOException {
            out.write(param);
        }
/*				public void close() throws IOException
				{
					out.close();
				}
				public void flush() throws IOException
				{
					out.flush();
				}
				public void write(byte[] b) throws IOException
				{
					out.write(b);
				}
				public void write(byte[] b, int off, int len) throws IOException
				{
					out.write(b,off,len);
				}
				public void print(String s)
				{
					String a=s;
				}
				public void print(char c)
				{
					char a=c;
				}*/
		}
}